Ext.define('yiyuan.view.Main', {
    extend: 'Ext.Container',
    xtype: 'main',
    requires: [ 'Ext.List', 'Ext.Img'],
    id:'main_id',
    config: {
        items: [
            {
                docked: 'top',
                xtype: 'toolbar',
                title: '掌上医院'
            },
            {
                xtype: "carousel",
                cls: "main_carousel",
                id: "main_carousel_id",
                indicator:false,
                items: [
                    {
                        xtype: 'panel',
                        html: "<img src='resources/images/pic.png'/ >",
                        listeners:{
                            painted:function(p){
                                p.on("tap",function(){
                                    var ej=Ext.create("yiyuan.view.Erji");
                                    ej.down("toolbar").setTitle("手机就医,从这里开始");
                                    ej.down("img").setSrc("resources/images/car_detail.png");
                                    Ext.Viewport.setActiveItem(ej);
                                })
                            }
                        }
                    },
                    {
                        xtype: 'panel',
                        html: "<img src='resources/images/bg_pic.png'/ >",
                        listeners:{
                            painted:function(p){
                                p.on("tap",function(){
                                    var ej=Ext.create("yiyuan.view.Erji");
                                    ej.down("toolbar").setTitle("手机就医,从这里开始");
                                    ej.down("img").setSrc("resources/images/car_detail.png");
                                    Ext.Viewport.setActiveItem(ej);
                                })
                            }
                        }
                    }
                ],
                listeners: {
                    initialize: function (cal) {
                        si=setInterval(function () { //设定2.5秒钟切换一次
                            Ext.getCmp("main_carousel_id").next(); //切换的方法
                            if (Ext.getCmp("main_carousel_id").getActiveIndex() === 1) {
                                Ext.getCmp("main_carousel_id").setActiveItem(0);
                            }
                        }, 4000);
                    }
                }
            },
            {
                xtype: "dataview",
                cls: "main_dataview",
                id: "main_dv_id",
                scrollable: null,
                store: "MainDataViewStore"
            },
            {
                xtype: "panel",
                cls:"main_bottom",
                docked:"bottom",
                id:"main_bottom_panel",
                scrollable: null,
                html:"<div class='imgDiv2'><img src='resources/images/btn_login.png' alt='login'/ ></div><div class='imgDiv2'><img src='resources/images/btn_more.png' alt='more'/ ></div>",
                listeners:{
                    painted:function(p){
                        p.on("tap",function(e){
                            var lm=Ext.create("yiyuan.view.Erji");
                            if(e.target.alt=='login'){
                                lm.down("toolbar").setTitle("登录");
                                lm.down("img").setSrc("resources/images/login_bg.png");
                            }else{
                                lm.down("toolbar").setTitle("更多");
                                lm.down("img").setSrc("resources/images/more_bg.png");
                            }
                            Ext.Viewport.setActiveItem(lm)
                        })
                    }
                }
            }
        ],
        listeners: {
            initialize: function () {
                var clientHeight = document.body.clientHeight;
                var c = clientHeight - 46;
                Ext.getCmp('main_carousel_id').setHeight(c * 0.25);
                Ext.getCmp('main_dv_id').setHeight(c * 0.65);
                Ext.getCmp('main_bottom_panel').setHeight(c * 0.1);
                var dataH = Ext.getCmp("main_dv_id").getHeight();
                var dataViewDivHeight = dataH*0.25-14;
                Ext.getCmp("main_dv_id").setItemTpl('<div style="height:' + dataViewDivHeight + 'px"><img src="{img_url}"/></div>');
            }
        }
    }

});
